//
//  ZFTabBarViewController.m
//  CustomTabBar
//
//  Created by 浙江择富 on 2018/1/18.
//  Copyright © 2018年 浙江择富. All rights reserved.
//

#import "ZFTabBarViewController.h"
#import "ZFTabBar.h"
#import "UIImage+image.h"

#import "BFBaseNavController.h"
@interface ZFTabBarViewController ()

@end

@implementation ZFTabBarViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
//    [self.tabBarController ]
//    self.navigationController.navigationBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear: animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    [self createTabBar];
    [self setupTabbarTextConfig];
    [self addChildViewContollers];
}

//自定义tabbar代替系统的TabBar
- (void)createTabBar{
    
    ZFTabBar *tabbar = [[ZFTabBar alloc] init];
    [self setValue:tabbar forKey:@"tabBar"];
}
//设置TabBar的字体
- (void)setupTabbarTextConfig{
    
    NSMutableDictionary *attrus = [NSMutableDictionary dictionary];
    attrus[NSFontAttributeName]  = [UIFont systemFontOfSize:12];
    attrus[NSForegroundColorAttributeName] =[UIColor lightGrayColor];
    
    NSMutableDictionary *selectAttrus =[NSMutableDictionary dictionary];
    selectAttrus[NSForegroundColorAttributeName] =[UIColor blackColor];
    
    UITabBarItem *item =[UITabBarItem appearance];
    [item setTitleTextAttributes:attrus forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectAttrus forState:UIControlStateSelected];
    
    //设置背景图片
    //    [[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
    [[UITabBar appearance] setBackgroundColor:[UIColor whiteColor]];
    //去除 TabBar 自带的顶部阴影  去掉顶部黑线
    [[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
}
//创建TabBar
-(void)createTabbarItemConfigureWith:(NSString *)vcString  title:(NSString *)title image:(NSString *)imageName selectImage:(NSString *)selectImageName{
    
    UIViewController *vc =[[NSClassFromString(vcString) alloc] init];
    BFBaseNavController *Navc =[[BFBaseNavController alloc] initWithRootViewController:vc];
//   [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
//    [Navc.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
    
//    Navc.navigationBar.barTintColor = [UIColor whiteColor];
//    Navc.navigationBar.translucent = NO;
    
    vc.tabBarItem.title =title;
//    vc.navigationItem.title =title;
    
    
    vc.tabBarItem.image =[UIImage imageNameWithOriginMode:imageName];
    vc.tabBarItem.selectedImage =[UIImage imageNameWithOriginMode:selectImageName];
    
    [self addChildViewController:Navc];
}

//添加控制器
-(void)addChildViewContollers{
    
    [self createTabbarItemConfigureWith:@"BFHomeViewController" title:@"首页" image:@"iconHomeNor" selectImage:@"iconHomeClick"];
    
    [self createTabbarItemConfigureWith:@"BFMarketViewController" title:@"营销" image:@"iconMarketNormal" selectImage:@"iconMarketClick"];
    
    [self createTabbarItemConfigureWith:@"BFPersonCenterController" title:@"我的" image:@"iconINor" selectImage:@"iconIClick"];
    
   
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
